package com.zjw.spring_ai;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.content.Media;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.util.List;

@RestController
public class MultiModelController {

    @Resource
    private OpenAiChatModel openAiChatModel;

    @RequestMapping(value = "/ai/multi")
    public Object multi(@RequestParam("msg") String msg,@RequestParam("imageUrl") String imageUrl) {

        UserMessage userMessage = new UserMessage(msg, List.of(new Media(MimeTypeUtils.IMAGE_PNG, URI.create(imageUrl))));

        ChatResponse chatResponse = openAiChatModel.call(new Prompt(userMessage));

        String text = chatResponse.getResult().getOutput().getText();
        System.out.println(text);
        return text;
    }
}

